#ifndef __MODBUS_HANDLER_H__
#define __MODBUS_HANDLER_H__

#include <arpa/inet.h>
#include <errno.h>
#include <modbus/modbus.h>
#include <pthread.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <time.h>
#include <unistd.h>
#include "../debug.h"
#include "modbus_config.h"
#include "modbus_tcp_slave.h"
#include "modbus_tcp_master.h"
#include "../comm_monitor.h"
#include "../TableInterface/hmi_table_interface.h"
#include "../TableInterface/ems_table_interface.h"
#include "../TableInterface/lc_table_interface.h"

#define CONNECTION_DEV_NUM 5

int modbus_slave_handler_HMIhandler_ReadHoldReg(modbus_mapping_t *mb_map, struct modbus_info_s *modbus_info);

int modbus_slave_handler_HMIhandler_WriteSingleReg(modbus_mapping_t * mb_map, struct modbus_info_s * modbus_info);

int modbus_slave_handler_HMIhandler_WriteMultiReg(const uint8_t *req, modbus_mapping_t *mb_map, struct modbus_info_s *modbus_info);

int modbus_slave_handler_HMIhandler(modbus_t *ctx, const uint8_t *req, int req_length, modbus_mapping_t *mb_map, struct modbus_info_s *modbus_info);

int modbus_slave_handler_EMShandler_ReadHoldReg(modbus_mapping_t *mb_map, struct modbus_info_s *modbus_info);

int modbus_slave_handler_EMShandler_WriteSingleReg(modbus_mapping_t *mb_map, struct modbus_info_s *modbus_info);

int modbus_slave_handler_EMShandler_WriteMultiReg(const uint8_t *req, modbus_mapping_t *mb_map, struct modbus_info_s *modbus_info);

int modbus_slave_handler_EMShandler(modbus_t *ctx, const uint8_t *req, int req_length, modbus_mapping_t *mb_map, struct modbus_info_s *modbus_info);

int modbus_slave_handler_LChandler_ReadHoldReg(modbus_mapping_t *mb_map, struct modbus_info_s *modbus_info);

int modbus_slave_handler_LChandler_WriteSingleReg(modbus_mapping_t *mb_map, struct modbus_info_s *modbus_info);

int modbus_slave_handler_LChandler_WriteMultiReg(const uint8_t *req, modbus_mapping_t *mb_map, struct modbus_info_s *modbus_info);

int modbus_slave_handler_LChandler(modbus_t *ctx, const uint8_t *req, int req_length, modbus_mapping_t *mb_map, struct modbus_info_s *modbus_info);

int modbus_recv_message_handler(modbus_t *ctx, const uint8_t *req, int req_length, modbus_mapping_t *mb_map, struct modbus_info_s *modbus_info);

int modbus_send_message_handler(modbus_t *ctx, Modbus_info_t *modbus_info, uint16_t *pBuf);

#endif

